#include "CEC2017_F6.h"

namespace Solver
{

CEC2017_F6::CEC2017_F6(std::size_t dim):BaseTestFun(dim, FunType_E::CEC2017_F6_E, DifficultyLevel_E::Easy_E, "CEC2017_F6", "")
{
    passY_ = 1e-12;
    bestY_ = 0;
}

CEC2017_F6::~CEC2017_F6()
{

}

value_t CEC2017_F6::calcMinFun(const VectorXd_t &x)
{
    //1.
    const std::size_t num = x.size();
    if (num < 2)
    {
        return 0;
    }

    //2.
    value_t sum(gFun(x[x.size() - 1], x[0]));
    for (std::size_t i = 1; i != num; ++i)
    {
        sum += gFun(x[i-1], x[i]);
    }

    return sum + num * 0.5;
}

value_t CEC2017_F6::gFun(value_t x, value_t y) const
{
    value_t t = x * x + y * y;
    return (std::pow(std::sin(std::sqrt(t)), 2) - 0.5) / std::pow(1 + 0.001 * t, 2);
}

}